package com.mq.dao;

import com.mq.bean.User;
import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.Result;
import org.jfaster.mango.annotation.Results;
import org.jfaster.mango.annotation.ReturnGeneratedId;
import org.jfaster.mango.annotation.SQL;

import java.util.List;

/**
 * TODO 增加注释
 *
 * @author MangoG
 * @version 1.0
 * @since 2018-02-03 15:45:11
 */
@DB(table="t_user")
@Results({
        @Result(column = "n_id", property = "id"),
        @Result(column = "c_user_name", property = "userName"),
        @Result(column = "c_pass_word", property = "passWord"),
        @Result(column = "c_role", property = "role")
})
public interface IUserDao {
    String COLUMNS = "n_id, c_user_name, c_pass_word, c_role";

    @ReturnGeneratedId
    @SQL("INSERT INTO #table(" + COLUMNS + ") VALUES (:id, :userName, :passWord, :role)")
    long save(User user);

    @SQL("INSERT INTO #table(" + COLUMNS + ") VALUES (:id, :userName, :passWord, :role)")
    void save(List<User> users);

    @SQL("UPDATE #table SET n_id = :id, c_user_name = :userName, c_pass_word = :passWord, c_role = :role WHERE n_id = :id")
    void update(User user);

    @SQL("SELECT " + COLUMNS + " FROM #table WHERE n_id = :1 ")
    User get(Long id);

    @SQL("SELECT " + COLUMNS + " FROM #table")
    List<User> list();

    @SQL("DELETE FROM #table WHERE n_id = :1")
    void del(Long id);

    @SQL("SELECT " + COLUMNS + " FROM #table WHERE c_user_name=:userName and c_pass_word=:passWord ")
    User doUserLogin(User user);
}